<template>
  <div class="dashboard-container">
    <div class="app-container">
      <!-- 路由params传参 -->
      <!-- 员工详情{{ $route.params.id }} -->
      <!-- 路由传参 -->
      <!-- {{ $route.query.age }} -->

      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账号设置">
            <el-form ref="formRef" :model="form" :rules="rules" label-width="180px" style="width:400px">
              <el-form-item label="用户名" prop="username">
                <el-input v-model="form.username"></el-input>
              </el-form-item>
              <el-form-item label="密码" prop="password">
                <el-input v-model="form.password" show-password></el-input>
              </el-form-item>
              <el-button type="primary" size="small" @click="onSubmit">更新</el-button>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <user-info></user-info>
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <job-info></job-info>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getEmployeeBaseInfo, saveUserDetailById } from './employees'
import jobInfo from './components/jobInfo'
import userInfo from './components/userInfo'
export default {
  name: 'DetailIndex',
  components: {
    jobInfo,
    userInfo
  },
  props: {
    id: {
      type: [Number, String],
      required: true
    }
  },
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入名字', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  async created() {
    //  * 获取员工的基本信息
    this.form = await getEmployeeBaseInfo(this.id)
    this.form.password = ''
  },
  mounted() {},
  methods: {
    async onSubmit() {
      //  * 保存员工的基本信息
      await saveUserDetailById(this.form)
      this.$message.success('操作成功')
    }
  }
}
</script>

  <style lang="scss" scoped>

  </style>
